<template>
	<view>
		<view class="header">
			<u-navbar
				:background="{ backgroundColor: '#3478F2' }"
				back-icon-color="#fff"
				back-icon-name="arrow-left"
				back-icon-size="40"
				:custom-back="back"
				title="紧急联系人"
				title-color="#fff"
				title-size="40"
				title-bold
			></u-navbar>
		</view>
		<scroll-view scroll-top="0" scroll-y="true" :style="`height:${scrollHeight}px`">
			<view class="page" @click.stop="handleDec">
				<!-- 联系人1 -->
				<view class="box">
					<view class="title">
						<view class="xing">*</view>
						<view class="title_dec">紧急联系人1</view>
					</view>
					<u-field v-model="form.person1.name" label="姓名" input-align="right" maxlength="10" clearable placeholder="请填写"></u-field>
					<view class="posit1">
						<text>关系</text>
						<view class="po_right" @click.stop="handleNum">
							<view class="po_text">
								<span class="relation">{{ form.person1.relation }}</span>
							</view>
							<u-icon name="arrow-down" color="#BDBDBB" size="20"></u-icon>
						</view>
						<view class="option1" v-if="isActive" ref="closeOpt">
							<view
								class="opt_item"
								v-for="item in option"
								:key="item.value"
								:class="active == item.value ? 'active' : ''"
								@click.stop="handleItem(item.value)"
							>
								{{ item.value }}
							</view>
						</view>
					</view>
					<u-field v-model="form.person1.phone" label="联系电话" input-align="right" maxlength="11" type="number" clearable placeholder="请填写"></u-field>
				</view>
				<!-- 联系人2 -->
				<view class="box" style="margin-top: 24rpx">
					<view class="title">
						<view class="xing">*</view>
						<view class="title_dec">紧急联系人2</view>
					</view>
					<u-field v-model="form.person2.name" label="姓名" input-align="right" maxlength="10" clearable placeholder="请填写"></u-field>
					<view class="posit2">
						<text>关系</text>
						<view class="po_right" @click.stop="handleNum1">
							<view class="po_text">
								<span class="relation">{{ form.person2.relation }}</span>
							</view>
							<u-icon name="arrow-down" color="#BDBDBB" size="20"></u-icon>
						</view>
						<view class="option1" v-if="isActive1" ref="closeOpt">
							<view
								class="opt_item1"
								v-for="item in option"
								:key="item.value"
								:class="active1 == item.value ? 'active' : ''"
								@click.stop="handleItem1(item.value)"
							>
								{{ item.value }}
							</view>
						</view>
					</view>
					<u-field v-model="form.person2.phone" label="联系电话" input-align="right" type="number" maxlength="11" clearable placeholder="请填写"></u-field>
				</view>
				<view class="pd">
					<view class="btn headle" @click="submit">提交</view>
					<view class="tips1">
						<image src="/static/icon/dun-pai@3x.png" mode="scaleToFill" />
						<text>国家级数据加密保护，仅用于贷款审核</text>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import { mixin } from '@/utils/mixins'
export default {
	mixins: [mixin],
	data() {
		return {
			active: '夫妻',
			isActive: false,
			option: [{ value: '夫妻' }, { value: '父亲' }, { value: '母亲' }, { value: '子女' }, { value: '兄弟姐妹' }, { value: '朋友' }, { value: '同事' }],
			form: {
				person1: {
					name: '',
					relation: '夫妻',
					phone: ''
				},
				person2: {
					name: '',
					relation: '父亲',
					phone: ''
				}
			},
			active1: '夫妻',
			isActive1: false
		}
	},
	methods: {
		submit() {
			if (this.form.person1.name == '' || this.form.person2.name == '') {
				uni.showToast({
					title: '请输入联系人姓名',
					icon: 'none'
				})
				return
			}
			if (!this.$u.test.mobile(this.form.person1.phone)) {
				uni.showToast({
					title: '请输入合法手机号',
					icon: 'none'
				})
				return
			}
			if (!this.$u.test.mobile(this.form.person2.phone)) {
				uni.showToast({
					title: '请输入合法手机号',
					icon: 'none'
				})
				return
			}
			console.log(this.form)
			uni.navigateTo({
				url: '/pages/financial/replenish'
			})
		},
		//点击页面下拉框隐藏
		handleDec() {
			this.isActive = false
			this.isActive1 = false
		},
		handleNum() {
			this.isActive = !this.isActive
		},
		handleItem(value) {
			this.active = value
			this.form.person1.relation = value
			setTimeout(() => {
				this.isActive = false
			}, 80)
		},
		handleNum1() {
			this.isActive1 = !this.isActive1
		},
		handleItem1(value) {
			this.active1 = value
			this.form.person2.relation = value
			setTimeout(() => {
				this.isActive1 = false
			}, 80)
		},
		back() {
			uni.switchTab({
				url: '/pages/financial/index'
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.page {
	background: #fff;
	height: 100%;
	padding-left: 32rpx;
	padding-right: 32rpx;
	position: relative;
}
.box {
	box-sizing: border-box;
	padding-top: 56rpx;
}
.title {
	align-items: center;
	display: flex;
	font-family: PingFang SC;
	.xing {
		height: 50rpx;
		font-size: 36rpx;
		font-weight: bold;
		color: #fc1f1f;
		margin-left: 6rpx;
	}
	.title_dec {
		height: 50rpx;
		font-size: 36rpx;
		font-weight: bold;
		color: #333333;
	}
}
::v-deep .u-field {
	color: #969799;
	padding-left: 24rpx;
	height: 108rpx;
}
::v-deep .uni-input-input {
	color: #333333;
}
.relation {
	display: inline-block;
	// width: 80rpx;
	margin-right: 26rpx;
	vertical-align: middle;
	text-align: center;
}
.mon_img {
	width: 42rpx;
	height: 26rpx;
	vertical-align: middle;
}
.posit1,
.posit2 {
	position: relative;
	display: flex;
	justify-content: space-between;
	border-bottom: 2rpx solid #f3f3f3;
	height: 108rpx;
	line-height: 108rpx;
	padding-left: 24rpx;
	padding-right: 24rpx;
	font-size: 28rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #969799;
	.po_right {
		display: flex;
	}
	.po_text {
		color: #333333;
	}
	.option1,
	.option1 {
		width: 218rpx;
		height: 616rpx;
		box-shadow: 0px 0px 30px rgba(0, 0, 0, 0.25);
		position: absolute;
		top: 80rpx;
		right: 50rpx;
		background-color: #ffffff;
		z-index: 3;
		.opt_item,
		.opt_item1 {
			box-sizing: border-box;
			width: 218rpx;
			height: 88rpx;
			background: #ffffff;
			border-bottom: 2rpx solid #e4e4e4;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #333333;
			text-align: center;
			opacity: 1;
			&:last-child {
				border: 0;
			}
		}
		.active {
			color: #3478f2;
		}
	}
}
.pd {
	padding: 0 32rpx;
	position: absolute;
	bottom: 200rpx;
	width: 100vw;
	left: 0;
}
.btn {
	height: 92rpx;
	background: linear-gradient(270deg, #0481fe 0%, #40c5fe 100%);
	line-height: 92rpx;
	text-align: center;
	border-radius: 70rpx;
	font-size: 36rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #ffffff;
}
.tips1 {
	margin-top: 16rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 28rpx;
	font-family: PingFang SC;
	font-weight: 400;
	color: #bdbdbd;
	image {
		width: 24rpx;
		height: 28rpx;
		margin-right: 12rpx;
	}
}
</style>
